package at.ac.tuwien.mg.wh.client;

import java.util.List;

import javax.naming.InitialContext;

import org.activiti.engine.delegate.DelegateExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.ac.tuwien.mg.wh.WarehouseBeanRemote;
import at.ac.tuwien.mg.wh.dto.ItemDTO;

public class CancelBookingClient extends Client {

	private static Logger log = LoggerFactory.getLogger(CancelBookingClient.class);

	@SuppressWarnings({ "unchecked" })
	@Override
	public void execute(DelegateExecution execution) throws Exception {

		InitialContext ctx = new InitialContext();
		WarehouseBeanRemote bean = lookupStateless(ctx);
		
		//////
		
		List<ItemDTO> toBook = (List<ItemDTO>) execution.getVariable("toBook");
		Long userId = toLong(execution.getProcessInstanceId().toString());

		bean.cancelBookedItems(toBook, userId);
		
		log("[CANCEL BOOKED]\n"+toBook+" for user: "+userId);
		
		//////
		
		closeContext(ctx);
	}
}
